home *** CD-ROM | disk | FTP | other *** search
- Imports System.Data.SqlClient
-
- Public Class SingleValueDataBindingForm
- Inherits System.Web.UI.Page
- Protected WithEvents txtType As System.Web.UI.WebControls.TextBox
- Protected WithEvents txtPrice As System.Web.UI.WebControls.TextBox
- Protected WithEvents txtTitle As System.Web.UI.WebControls.TextBox
- Protected WithEvents ddlTitles As System.Web.UI.WebControls.DropDownList
-
- #Region " Web Form Designer Generated Code "
-
- 'This call is required by the Web Form Designer.
- <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
-
- End Sub
-
- Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
- 'CODEGEN: This method call is required by the Web Form Designer
- 'Do not modify it using the code editor.
- InitializeComponent()
- End Sub
-
- #End Region
-
- ' Define a Public DataRow variable that is visible from <%# %> expressions.
- Public Titles As DataRow
-
- Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- ' Fill the
- If Not Page.IsPostBack Then
- ' Fill the data table and then close the connection.
- Dim cn As New SqlConnection(SqlPubsConnString)
- Dim da As New SqlDataAdapter("SELECT * FROM Titles", cn)
- Dim dt As New DataTable()
- da.Fill(dt)
- ' Store the DataTable in a Session variable.
- Session("TitlesDataTable") = dt
- ' Manually fill the Items collection of the ddlTitles control.
- Dim dr As DataRow
- For Each dr In dt.Rows
- ddlTitles.Items.Add(dr("title").ToString)
- Next
- ddlTitles.SelectedIndex = 0
- ' Prepare the Titles variable for binding
- Titles = dt.Rows(0)
-
- ' Bind all controls.
- Me.DataBind()
- End If
-
- End Sub
-
- Private Sub ddlTitles_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlTitles.SelectedIndexChanged
- ' Retrieve the DataTable object from the session variable.
- Dim dt As DataTable = DirectCast(Session("TitlesDataTable"), DataTable)
- ' Prepare the Titles variable and do the data binding.
- Titles = dt.Rows(ddlTitles.SelectedIndex)
- Me.DataBind()
- End Sub
- End Class
-